package api

import (
	"github.com/gin-gonic/gin"
	"monitoring-api/service"
)

func AddWeb(c *gin.Context) {
	var service service.AddWebService
	if err := c.ShouldBind(&service); err == nil {
		userID, _ := c.Get("user_id")
		res := service.AddWeb(userID.(int64))
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}

func ListWeb(c *gin.Context) {
	var service service.ListWebService
	userID, _ := c.Get("user_id")
	res := service.List(userID.(int64))
	c.JSON(200, res)
}

func UpdateWeb(c *gin.Context) {
	var service service.UpdateWebService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Update(service.WebID)
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}

func DeleteWeb(c *gin.Context) {
	var service service.DeleteWebService
	if err := c.ShouldBind(&service); err == nil {
		res := service.Delete()
		c.JSON(200, res)
	} else {
		c.JSON(500, gin.H{
			"message": err.Error(),
		})
	}
}
